<!DOCTYPE html>
<html lang="en">
<!--header-->
<include file="Public:header"/>
<!--header-->
<section id="main-content">
    <section class="wrapper">
        <h3><i class="fa fa-angle-right"></i> 修改个人信息</h3>

        <!-- BASIC FORM ELELEMNTS -->
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb"><i class="fa fa-angle-right"></i> 个人信息</h4>
                    <form id="admin" class="form-horizontal style-form" method="post" action="{:U('add')}"  enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">个人头像</label>
                            <div class="col-sm-10">
                                <input type="file"  name="one" id="avatar" onchange='PreviewImage(this)' style="opacity: 0;display: block;cursor:pointer" />
                                <if condition="$list.img != NULL">
                                    <img class="ph-user"  src="{$list.img}" width="80" height="80" onclick="openFile()" style="cursor:pointer">
                                    <else/>
                                    <img class="ph-user" src="__PUBLIC__/img/wutu.jpg" alt="" width="80" height="80" onclick="openFile()" style="cursor:pointer">
                                </if>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10">
                                <input id="name" name="name" value="{$list.name}" type="text"  class="form-control" placeholder="请输入管理员姓名/昵称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">原始密码</label>
                            <div class="col-sm-10">
                                <input id="password" name="password"  type="password"  class="form-control" placeholder="请输入原始密码" style="float: left">
                                <span id="pass" style="float: left"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">新密码</label>
                            <div class="col-sm-10">
                                <input id="xin" name="xin"  type="password"  class="form-control" placeholder="请输入新密码" style="float: left">
                                <span id="pwd" style="float: left"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">确认新密码</label>
                            <div class="col-sm-10">
                                <input id="que_xin" name="que_xin"  type="password"  class="form-control" placeholder="请输入确认密码" style="float: left">
                                <span id="jpwd" style="float: left"></span>
                            </div>
                        </div>
                        <input type="hidden" id="che" name="id" value="{$list.id}">
                        <input type="hidden" name="img" value="{$list.img}">
                        <input type="hidden" name="que" value="{$que}">
                        <input type="hidden" name="status" value="{$list.status}">
                        <input type="hidden" name="type" value="{$list.type}">
                        <input type="hidden" name="store_id" value="{$list.store_id}">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                                <input  type="button" id="tianjia" class="btn btn-theme" value="保存" style="width: 150px;margin-left: 60px">
                                <input  type="reset" class="btn btn-warning" value="重置" style="width: 150px">
                            </div>
                        </div>
                    </form>
                </div>
            </div><!-- col-lg-12-->
        </div><!-- /row -->
    </section>
</section>
<!--footer-->
<include file="Public:footer"/>
<!--footer-->
<script type="text/javascript" src="__PUBLIC__/ui/lib/layer/2.4/layer.js"></script>
<script>
    //验证原始密码是否正确
    $("#password").on("blur", function () {
        var password = document.getElementById("password").value;
        if(password == ""){
            layer.tips('原始密码不能为空', '#pass');
            _pass = false;
        }else{
            $.ajax({
                url:"{:U('password')}",
                type:"post",
                data:{password:password},
                success:function (data) {
                    if(data.status == 2){
                        layer.tips('原始密码有误', '#pass');
                        _pass = false;
                    }else{
                        $("#pass").html("");
                        _pass = true;
                    }
                }
            })
        }
    })
    $("#xin").on("blur", function () {
        var xin =  $("#xin").val();
        if(xin == ""){
            layer.tips('新密码不能为空', '#pwd');
            _pwd = false;
        }else{
            $("#pwd").html("");
            _pwd = true;
        }
    })
    $("#que_xin").on("blur", function () {
        var que_xin =  $("#que_xin").val();
        var xin     =  $("#xin").val();
        if(que_xin == "" || xin != que_xin){
            layer.tips('两次输入密码不一致', '#jpwd');
            _jpwd = false;
        }else{
            $("#jpwd").html("");
            _jpwd = true;
        }
    })
    $("#tianjia").click(function(){
        if(_pass == true && _pwd == true && _jpwd == true){
            var name     = document.getElementById("name").value;
            var xin      = document.getElementById("xin").value;
            var che      = document.getElementById("che").value;
            $.ajax({
                type:"post",
                data:{name:name,password:xin,che:che},
                url:"{:U('checks')}",
                success:function (res) {
                    if(res.status == 1){
                        layer.open({
                            title: '个人信息修改提示：',
                            content: res.info
                        });
                    }
                    if(res.status == 2){
                        document.getElementById("admin").submit();
                    }
                }
            })
        }else{
            layer.open({
                title: '个人信息修改提示：'
                ,content: "信息修改不成功,如忘记原始密码请与上层联系！"
            });
            _pass = false;
        }
    });
    //图片上传
    function openFile(){
        return  $("#avatar").click();
    }
    function PreviewImage(imgFile)
    {
        var filextension=imgFile.value.substring(imgFile.value.lastIndexOf("."),imgFile.value.length);
        var o=imgFile.files[0];
        filextension=filextension.toLowerCase();
        if ((filextension!='.jpg')&&(filextension!='.jpeg')&&(filextension!='.png')&&(filextension!='.bmp'))
        {

            imgFile.focus();
        }else if(o.size > 2097152){
            imgFile.focus();
        }
        else
        {
            var path;
            path=window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
            $('.ph-user').attr({src:path});
        }
    }
</script>

</body>
</html>
